package jdos.hardware;

import jdos.Dosbox;
import jdos.cpu.Paging;
import jdos.hardware.VGA_memory.VRAM;
import jdos.ints.Int10_modes;
import jdos.misc.Log;
import jdos.types.LogSeverities;
import jdos.types.LogTypes;
import jdos.util.Ptr;

public class VGA_memory {

	final public class VRAM {
		public static int[] direct = new int[1024 * 128];

		public static /*Bit8u*/short readb(/*HostPt*/int address) {
			return (short) ((direct[(address >>> 2)] >>> ((address & 0x3) << 3)) & 0xFF);
		}
	    public static /*Bit32u*/int readd(/*HostPt*/int address) {
            return direct[address >>> 2];
	    }
	    public static /*Bit32u*/int writed(/*HostPt*/int address, int val) {
            return direct[address >>> 2] = val;
	    }

		public static void writeb(/*HostPt*/int address, /*Bit8u*/ int value) {
			int off = (address & 0x3) << 3;
			int[] local = direct;
			int mask = ~(0xFF << off);
			int index = (address >>> 2);
			int val = local[index] & mask | (value & 0xFF) << off;
			local[index] = val;
		}

	}
    public static int readbA0(/*PhysPt*/int addr) {
		return VRAM.readb(addr);
    }

    static int[] ExpandTable = new int[256];
    static {
        for (int i=0;i<256;i++) {
            ExpandTable[i]=i | (i << 8)| (i <<16) | (i << 24);
        }
    }

	public static void writebA0(/*PhysPt*/int addr, /*Bitu*/int val) {
		if (VGA_seq.chained) {
			VRAM.writeb(addr, val);
		} else {
			addr <<= 2;
			/*Bit32u*/int data = ExpandTable[val & 0xFF];//ModeOperation(val);
			int d = VRAM.readd(addr);
			d &= VGA_seq.full_not_map_mask;
			d |= (data & VGA_seq.full_map_mask);
			VRAM.writed(addr, d);
		}
	}

}
